注意JFrame中的容器
package cn.usts.edu.lesson04;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo02 {
public static void main(String[] args) {
new TestJFrameDemo02().init();
}
}
class TestJFrameDemo02 extends JFrame{
public void init(){
this.setBounds(100,100,400,300);
this.setVisible(true);
this.setTitle("hello");
JLabel label = new JLabel("这是我的第二个JFrame程序");
.setHorizontalAlignment(SwingConstants.CENTER);// 水平对准
label
this.add(label); // 添加组件
Container container = this.getContentPane();// 获取(内容面板)当前容器 有点awt中的getSource的味道
.setBackground(Color.orange);//设置背景色
container
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);// 关闭按钮
}
}